package com.dc.pay.callback.service;

import com.dc.pay.callback.template.AbstractPayCallbackTemplate;
import com.dc.pay.callback.template.factory.TemplateFactory;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
public class PayAsyncCallbackService {

    private static final String UNIONPAYCALLBACK_TEMPLATE = "unionPayCallbackTemplate";

    private static final String ALIPAYCALLBACK_TEMPLATE = "alipayCallbackTemplate";

    /**
     * @author: KEYD
     * @Date: 2020/1/13 16:40
     * @Desc: 银联异步回调接口
     */
    @RequestMapping("/unionPayAsyncCallback")
    public String unionPayAsyncCallback(HttpServletRequest req, HttpServletResponse resp) {
        //这样子也可以运行，但是太low
        //AbstractPayCallbackTemplate abstractPayCallbackTemplate = new UnionPayCallbackTemplate();
        //return abstractPayCallbackTemplate.asyncCallBack(req, resp);
        //使用模板工厂
        AbstractPayCallbackTemplate abstractPayCallbackTemplate = TemplateFactory.getPayCallbackTemplate(UNIONPAYCALLBACK_TEMPLATE);
        return abstractPayCallbackTemplate.asyncCallBack(req, resp);
    }

    @RequestMapping("/aliPayAsyncCallback")
    public String aliPayAsyncCallback(HttpServletRequest req, HttpServletResponse resp) {
        //使用模板工厂
        AbstractPayCallbackTemplate abstractPayCallbackTemplate = TemplateFactory.getPayCallbackTemplate(ALIPAYCALLBACK_TEMPLATE);
        return abstractPayCallbackTemplate.asyncCallBack(req, resp);
    }

    @RequestMapping("/alipaylocal")
    public String alipaylocal(HttpServletRequest req, HttpServletResponse resp) {
        return "支付成功";
    }
}
